#include <bits/stdc++.h>
#ifndef DEBUG
#define debug
#endif
using namespace std;
using i64 = int64_t;

void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; i ++) cin >> a[i];
  vector<array<vector<int>, 2>> dp(n + 2);
  // mp[i][0/1][k] 前 i 个数， 第 i 个数不选/选，所能形成和为 k 的个数
  dp[0][0].push_back(0);
  for (int i = 1; i <= n / 2; i ++) {
    dp[i][0] = dp[i - 1][1];
    for (auto x : dp[i - 1][0]) {
      dp[i][1].push_back((x + a[i]) % m);
      dp[i][0].push_back(x);
    }
  }
  dp[n + 1][0].push_back(0);
  for (int i = n; i > n / 2; i --) {
    dp[i][0] = dp[i + 1][1];
    for (auto x : dp[i + 1][0]) {
      dp[i][1].push_back((x + a[i]) % m);
      dp[i][0].push_back(x);
    }
  }
  auto &left = dp[n / 2], &right = dp[n / 2 + 1];
  sort(left[0].begin(), left[0].end());
  sort(left[1].begin(), left[1].end());
  sort(right[0].begin(), right[0].end());
  sort(right[1].begin(), right[1].end());
  i64 ans = 0;
  for (auto x : left[0]) { // 右边第一个不选，左边最后一个选
    auto [L, R] = equal_range(right[1].begin(), right[1].end(), (m - x) % m);
    ans += (i64)(R - L);
  }
  for (auto x : right[0]) { // 左边最后一个不选，右边第一个选
    auto [L, R] = equal_range(left[1].begin(), left[1].end(), (m - x) % m);
    ans += (i64)(R - L);
  }
  for (auto x : right[0]) { // 两边都不选
    auto [L, R] = equal_range(left[0].begin(), left[0].end(), (m - x) % m);
    ans += (i64)(R - L);
  }
  cout << ans << endl;
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  int T = 1;
  // cin >> T;
  for (int cas = 1; cas <= T; cas ++) {
    // cout << "Case #" << cas << ": ";
    solve();
  }
  cerr << "Time: " << 1.0 * clock() << "ms" << endl;
}